package org.jeecg.modules.generator.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.jeecg.modules.generator.entity.SysGenerateModuleConfig;
import org.jeecg.modules.generator.service.SysGenerateModuleConfigService;
import org.jeecg.common.api.vo.Result;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.generator.vo.SysGenerateModuleConfigVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.jeecg.common.aspect.annotation.AutoLog;
import java.util.List;

/**
* @Description 生成模块路劲配置控制器
* @Author yangfeng
* @Date 2021-06-30 10:58:26
*/
@RestController
@RequestMapping(value="generator/MoudualPathConfig")
@Api(tags = "生成模块路劲配置")
public class SysGenerateModuleConfigController {

    @Autowired
    private SysGenerateModuleConfigService sysGenerateModuleConfigService;




    /**
    * 查询生成模块路劲配置分页数据
    * @param sysGenerateModuleConfigVo
    * @return
    */
    @ApiOperation(value = "生成模块路劲配置-分页查询")
    @AutoLog("生成模块路劲配置-分页查询")
    @GetMapping(value="list")
    public Result<IPage<SysGenerateModuleConfig>> list(SysGenerateModuleConfigVo sysGenerateModuleConfigVo){

        Result<IPage<SysGenerateModuleConfig>> result = new Result<>();
        QueryWrapper queryWrapper = sysGenerateModuleConfigVo.getQueryWrapper();
            if(StringUtils.isNotEmpty(sysGenerateModuleConfigVo.getProjectName())){
                queryWrapper.like("PROJECT_NAME",sysGenerateModuleConfigVo.getProjectName());
            }
            if(StringUtils.isNotEmpty(sysGenerateModuleConfigVo.getDataSourceId())){
                queryWrapper.like("DATA_SOURCE_ID",sysGenerateModuleConfigVo.getDataSourceId());
            }
        IPage<SysGenerateModuleConfig> pageList = sysGenerateModuleConfigService.page(sysGenerateModuleConfigVo.getPage(),queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 根据主键查询数据源配置表对象数据
     * @return
     */
    @GetMapping(value="allList")
    public Result allList(){
        List<SysGenerateModuleConfig> sysGenerateModuleConfigList = sysGenerateModuleConfigService.list();
        return Result.ok(sysGenerateModuleConfigList);
    }



    /**
    * 根据主键查询生成模块路劲配置对象数据
    * @param id
    * @return
    */
    @GetMapping(value="queryById/{id}")
    public Result queryById(@PathVariable("id")String id){

        SysGenerateModuleConfig sysGenerateModuleConfig = sysGenerateModuleConfigService.getById(id);
        if(sysGenerateModuleConfig != null){
           return Result.ok(sysGenerateModuleConfig);
        }else{
            return Result.error("未找到查询对象！");
        }
    }
    /**
    * 生成模块路劲配置新增保存
    * @param sysGenerateModuleConfig
    * @return
    */
    @ApiOperation(value = "生成模块路劲配置-新增保存")
    @AutoLog("生成模块路劲配置-新增保存")
    @PostMapping(value="add")
    public Result add(@RequestBody SysGenerateModuleConfig sysGenerateModuleConfig){
        sysGenerateModuleConfigService.save(sysGenerateModuleConfig);
        return Result.ok("新增生成模块路劲配置成功！");
    }

    /**
    * 生成模块路劲配置修改保存
    * @param sysGenerateModuleConfig
    * @return
    */
    @ApiOperation(value = "生成模块路劲配置-修改保存")
    @AutoLog("生成模块路劲配置-修改保存")
    @PutMapping(value="edit")
    public Result edit(@RequestBody SysGenerateModuleConfig sysGenerateModuleConfig){

        SysGenerateModuleConfig generateModuleConfig = sysGenerateModuleConfigService.getById(sysGenerateModuleConfig.getId());
        if(generateModuleConfig != null){
            sysGenerateModuleConfigService.updateById(generateModuleConfig);
            return Result.ok("修改生成模块路劲配置成功！");
        }else{
            return Result.error("修改生成模块路劲配置不存在！");
        }
    }
    /**
    *生成模块路劲配置删除
    * @param id
    * @return
    */

    @ApiOperation(value = "生成模块路劲配置-删除")
    @AutoLog("生成模块路劲配置-删除")
    @DeleteMapping(value="delete")
    public Result  delete(@RequestParam("id")String id){

        sysGenerateModuleConfigService.removeById(id);
        return Result.ok("删除生成模块路劲配置数据成功！");
    }
}
